package com.example.arithmeticleetcode.learnArithmetic.map;

import com.example.arithmeticleetcode.learnArithmetic.map.file.FileInfo;
import com.example.arithmeticleetcode.learnArithmetic.map.file.Files;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-21 16:16
 **/
public class TreeMapTest {

    public static void main(String[] args) {
        test2();
    }

    static void test1() {
        Map<String, Integer> map = new TreeMap<>();
        map.put("class", 2);
        map.put("public", 5);
        map.put("text", 8);
        map.put("public", 8);

        map.traversal(new Map.Visitor<String, Integer>() {
            @Override
            public boolean visit(String key, Integer value) {
                System.out.println(key + "======" + value);
                return false;
            }
        });
    }

    static void test2() {
        FileInfo fileInfo = Files.read("C:\\Users\\lx\\javaDev\\ideaProject\\fzExercise\\arithmetic-leetcode\\src\\main\\java\\com", new String[]{});
        System.out.println("文件数量：" + fileInfo.getFiles());
        System.out.println("代码行数：" + fileInfo.getLines());
        String[] words = fileInfo.words();
        System.out.println("单词数量：" + words.length);
        Map<String, Integer> map = new TreeMap<>();
        for (String word : words) {
            Integer count = map.get(word);
            map.put(word, count != null ? count++ : 1);
        }
        System.out.println("过滤后有：" + map.size());

    }
}
